---
title: "CP Survey Data Summary"
date: '`r format(Sys.Date(), format="%B %d, %Y")`'
output:
flexdashboard::flex_dashboard:
navbar:
- { title: "by Joyce Lee", href: "https://www.joyceylee.com", align: left }
theme: cerulean
vertical_layout: fill
orientation: rows
social: [ "twitter", "menu" ]
source_code: embed
---
```{r setup}
load("~/Box Sync/University of Michigan /Winter 2018/Coding_Dataviz/Week 7/Week7.RData")
library(knitr)
library(flexdashboard)
library(leaflet)
library(DT)
library(formattable)
library(rpivotTable)
library(ggplot2)
library(ggthemes)
library(plotly)
library(dplyr)
library(leaflet)
library(pander)
```
```{r colors}
mycolors<-c("red", "orange", "yellow", "green", "purple")
```
Interactive DataViz
=======================================
Row
---------------------------------------
###Quick overview of corporal punishment survey results
```{r}
valueBox(paste("Dashboards"),
color="success")
```
###Data from corporal punishment survey with 70 non-white participants
```{r}
valueBox(paste("Data Source"),
color="warning")
```
###Participants
```{r}
valueBox(length(cpdata$ResponseId),
icon="ion-ios-people")
```
###Average Age (Years)
```{r}
valueBox("32",
icon="ion-ios-personadd")
```
Row
---------------------------------------
###Ethnicity and Race
```{r}
r<- cpdata %>%
group_by(Q35) %>%
summarize(count=n()) %>%
plot_ly(x=~Q35,
y=~count,
color=I("dark blue"),
type="bar") %>%
layout(xaxis=list(title="Ethnicity or Race"),
yaxis=list(title="Count"))
r
```
### Gender
```{r, fig.width=3, fig.height=5}
g<-cpdata %>%
group_by(Q34) %>%
summarize(count=n()) %>%
plot_ly(labels=~Q34,
values=~count,
marker=list(colors=c("light blue", "gold"))) %>%
add_pie(hole=0.4)
g
```
### Relationship Status
```{r, fig.width=3, fig.height=5}
r<-cpdata %>%
group_by(Q37) %>%
summarize(count=n()) %>%
plot_ly(labels=~Q37,
values=~count,
marker=list(colors=c("pink", "grey", "magenta", "purple"))) %>%
add_pie(hole=0.4)
r
```
Row
---------------------------------------
### Education
```{r, fig.width=4}
e <- cpdata %>%
group_by(Q36) %>%
summarise(percent=n()) %>%
mutate(percent=percent/sum(percent)*100) %>%
plot_ly(x=~percent,
y=~Q36,
marker=list(color=mycolors),
type="bar") %>%
layout(xaxis=list(title="Percentage"),
yaxis=list(title="Education Level", showticklabels=FALSE))
e
```
### Income
```{r, fig.width=4, fig.height=5}
i<-cpdata %>%
group_by(Q41) %>%
summarize(count=n()) %>%
plot_ly(labels=~Q41,
values=~count,
marker=list(colors="Set1")) %>%
add_pie(hole=0.4)
i
```
### Corporal Punishment MTurk Participants by Geography
```{r}
m<-leaflet(data=cpdata,
height = 500,
width = 1000) %>%
setView(lng = mean(cpdata$LocationLongitude),
lat = mean(cpdata$LocationLatitude), zoom=3) %>%
addProviderTiles("Stamen.TonerLite", group = "Toner Lite")
m %>% addMarkers(lng = ~LocationLongitude,
lat = ~LocationLatitude,
popup = ~as.character(location))
```